import request from '@/utils/request'

export const notificationApi = {
  // 获取通知列表
  getNotifications(params = {}) {
    return request.get('/notifications', { params })
  },

  // 获取用户通知
  getUserNotifications(userId, params = {}) {
    return request.get(`/users/${userId}/notifications`, { params })
  },

  // 创建通知
  createNotification(notification) {
    return request.post('/notifications', notification)
  },

  // 批量发送通知
  sendBulkNotifications(notifications) {
    return request.post('/notifications/bulk', { notifications })
  },

  // 标记通知为已读
  markAsRead(notificationId) {
    return request.put(`/notifications/${notificationId}/read`)
  },

  // 批量标记已读
  markBulkAsRead(notificationIds) {
    return request.put('/notifications/bulk-read', { ids: notificationIds })
  },

  // 标记所有通知为已读
  markAllAsRead(userId) {
    return request.put(`/users/${userId}/notifications/mark-all-read`)
  },

  // 删除通知
  deleteNotification(notificationId) {
    return request.delete(`/notifications/${notificationId}`)
  },

  // 获取未读通知数量
  getUnreadCount(userId) {
    return request.get(`/users/${userId}/notifications/unread-count`)
  },

  // 获取通知设置
  getNotificationSettings(userId) {
    return request.get(`/users/${userId}/notification-settings`)
  },

  // 更新通知设置
  updateNotificationSettings(userId, settings) {
    return request.put(`/users/${userId}/notification-settings`, settings)
  },

  // 订阅通知
  subscribe(userId, type, target) {
    return request.post('/notifications/subscribe', {
      userId, type, target
    })
  },

  // 取消订阅
  unsubscribe(userId, type, target) {
    return request.post('/notifications/unsubscribe', {
      userId, type, target
    })
  },

  // 获取通知模板列表
  getTemplates() {
    return request.get('/notification-templates')
  },

  // 创建通知模板
  createTemplate(template) {
    return request.post('/notification-templates', template)
  },

  // 更新通知模板
  updateTemplate(templateId, template) {
    return request.put(`/notification-templates/${templateId}`, template)
  },

  // 删除通知模板
  deleteTemplate(templateId) {
    return request.delete(`/notification-templates/${templateId}`)
  },

  // 预览通知模板
  previewTemplate(templateId, data = {}) {
    return request.post(`/notification-templates/${templateId}/preview`, data)
  },

  // 发送邮件通知
  sendEmail(emailData) {
    return request.post('/notifications/email', emailData)
  },

  // 发送短信通知
  sendSMS(smsData) {
    return request.post('/notifications/sms', smsData)
  },

  // 发送推送通知
  sendPush(pushData) {
    return request.post('/notifications/push', pushData)
  },

  // 发送站内信
  sendInternalMessage(messageData) {
    return request.post('/notifications/internal', messageData)
  },

  // 获取通知渠道配置
  getChannelConfig() {
    return request.get('/notifications/channels/config')
  },

  // 更新通知渠道配置
  updateChannelConfig(channelId, config) {
    return request.put(`/notifications/channels/${channelId}/config`, config)
  },

  // 测试通知渠道
  testChannel(channelId, testData) {
    return request.post(`/notifications/channels/${channelId}/test`, testData)
  },

  // 获取通知统计
  getNotificationStats(params = {}) {
    return request.get('/notifications/stats', { params })
  },

  // 获取通知发送记录
  getSendHistory(params = {}) {
    return request.get('/notifications/send-history', { params })
  },

  // 重新发送失败的通知
  retrySending(notificationId) {
    return request.post(`/notifications/${notificationId}/retry`)
  },

  // 创建通知规则
  createRule(rule) {
    return request.post('/notification-rules', rule)
  },

  // 获取通知规则列表
  getRules() {
    return request.get('/notification-rules')
  },

  // 更新通知规则
  updateRule(ruleId, rule) {
    return request.put(`/notification-rules/${ruleId}`, rule)
  },

  // 删除通知规则
  deleteRule(ruleId) {
    return request.delete(`/notification-rules/${ruleId}`)
  },

  // 启用/禁用通知规则
  toggleRuleStatus(ruleId, enabled) {
    return request.put(`/notification-rules/${ruleId}/status`, { enabled })
  }
}
